import request from '@/utils/request'

// 获取文章分类列表
const getCateListAPI = () => {
  return request({
    method: 'get',
    url: '/my/cate/list'
  })
}

// 添加文章分类
const addCateAPI = (addForm) => {
  return request({
    method: 'post',
    url: '/my/cate/add',
    data: addForm
  })
}

// 获取分类详情
const getCateDetailAPI = (id) => {
  return request({
    method: 'get',
    url: '/my/cate/info',
    params: {
      id
    }
  })
}

// 更新文章分类
const updateArtAPI = (editForm) => {
  return request({
    method: 'put',
    url: '/my/cate/info',
    data: editForm
  })
}

// 删除文章分类
const delCateAPI = (id) => {
  return request({
    method: 'delete',
    url: '/my/cate/del',
    params: {
      id
    }
  })
}

// 发布文章
const pubArticleAPI = (formData) => {
  return request({
    method: 'post',
    url: '/my/article/add',
    // formData不是一个普通对象，而是一个FormData对象
    data: formData
  })
}

// 获取文章列表
const getArtListAPI = (q) => {
  return request({
    method: 'get',
    url: '/my/article/list',
    params: q
  })
}

// 获取文章详情
const getArtDetailAPI = (id) => {
  return request({
    method: 'get',
    url: '/my/article/info',
    params: {
      id
    }
  })
}

// 删除文章
const delArtAPI = (id) => {
  return request({
    method: 'delete',
    url: '/my/article/info',
    params: {
      id
    }
  })
}
export {
  getCateListAPI,
  addCateAPI,
  getCateDetailAPI,
  updateArtAPI,
  delCateAPI,
  pubArticleAPI,
  getArtListAPI,
  getArtDetailAPI,
  delArtAPI
}
